package com.luna.serviceImpl;

import com.luna.beans.Book;
import com.luna.dao.BookDao;
import com.luna.service.BookService;

import java.util.List;

public class BookServiceImpl implements BookService {
    @Override
    public List<Book> bookList() {
        List<Book> list = null;
        BookDao bookDao = new BookDao();
        try {
            list = bookDao.selectAllBook();
        } catch (Exception ignored) {}
        return list;
    }

    @Override
    public Book getBook(int book_id) {
        Book book = null;
        BookDao bookDao = new BookDao();
        try {
            book = bookDao.selectByBookId(book_id);
        } catch (Exception ignored) {}
        return book;
    }

    @Override
    public boolean addBook(Book book) {
        BookDao bookDao = new BookDao();
        try {
            bookDao.insertBook(book);
        } catch (Exception _e) {
            System.out.println(_e);
            return false;
        }
        return true;
    }

    @Override
    public boolean dropBook(int book_id) {
        BookDao bookDao = new BookDao();
        try {
            bookDao.dropBookById(book_id);
        } catch (Exception _e) {
            return false;
        }
        return true;
    }

    @Override
    public boolean updateBook(int book_id, Book book) {
        BookDao bookDao = new BookDao();
        try {
            bookDao.updateBook(book_id, book);
        } catch (Exception _e) {
            return false;
        }
        return true;
    }
}
